<template>
  <view class="authWrap">
    <NavBar title="登录/注册"></NavBar>
    <AuthHeader></AuthHeader>
    <view class="content">
		<!-- #ifdef MP-WEIXIN -->
		<AuthWx :code="code"></AuthWx>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<AuthAccounts @closeAccounts="showAccounts" v-if="h5Accounts===true&&h5Addpassword===false" ></AuthAccounts>
		<AddPassword v-if="h5Accounts===false && h5Addpassword===true" :mobile="mobile"></AddPassword>
		<AuthH5 @showAccounts="showAccounts" v-if="h5Accounts===false&&h5Addpassword===false"></AuthH5>
		<!-- #endif -->
		<!-- #ifdef APP-PLUS -->
		<AuthApp @giveMobile="handleMobile"
				@loginAccountsStatus="loginAccountsStatus"
				v-if="accountsStatus===false&&showPassword===false"></AuthApp>
		<AddPassword @passwordStatus="handlePassStatus" v-else-if="showPassword===true&&accountsStatus===false" :mobile="mobile"></AddPassword>
		<AuthAccounts @loginAccountsStatus="loginAccountsStatus" v-else-if="accountsStatus===true&&showPassword===false"></AuthAccounts>
		<!-- #endif -->
    </view>
  </view>
</template>

<script>
import NavBar from '@/components/NavBar/NavBar'
import AuthHeader from './components/Auth-header.vue'
import AuthWx from './components/Auth-wx.vue'
import AuthH5 from './components/Auth-h5.vue'
import Register from './components/Register.vue'
import AuthApp from './components/Auth-app.vue'
import AddPassword from './components/AddPassword.vue'
import AuthAccounts from './components/Auth-accounts.vue'
export default {
  components: {
    NavBar,
    AuthHeader,
	AuthWx,
	AuthH5,
	Register,
	AuthApp,
	AddPassword,
	AuthAccounts
  },
  data () {
    return {
      code: '',
	  h5Accounts:false,
	  h5Addpassword:false,
	  showPassword:false,
	  accountsStatus:false,
	  mobile:''
    }
  },
  onShow () {
	//#ifdef MP-WEIXIN
    this.getWxCode()
	//#endif
  },
  onReady(){
	//#ifdef H5
	uni.$on('h5AddPassword',this.showAddPassword) 
	//#endif
  },
  onUnload(){
	//#ifdef H5
	uni.$off('h5AddPassword',this.showAddPassword) 
	//#endif 
  },
  methods: {
	//#ifdef MP-WEIXIN
     async getWxCode () {
          const res = await uni.login({ provider: 'weixin' })
          const [err, data] = res
          if (data && data.code) {
            this.code = data.code
          }
        }
	//#endif
	//#ifdef H5
	showAccounts(boolean){
		this.h5Accounts = boolean
	},
	showAddPassword(data){
		this.h5Addpassword = data.show
		this.mobile = data.mobile
	}
	//#endif
	//#ifdef APP-PLUS
	handleMobile(data){
		this.showPassword = data.show,
		this.mobile = data.mobile
	},
	loginAccountsStatus(boolean){
		this.accountsStatus=boolean
	},
	handlePassStatus(boolean){
		this.showPassword = boolean
	}
	//#endif
  }
}
</script>

<style lang="scss" scoped>

.authWrap {
  width: 100%;
  position: relative;
  .content {
    width: 90%;
    min-height: 500rpx;
    position: absolute;
    left: 5%;
    top: 500rpx;
    border-radius: 10rpx;
    box-shadow: 2rpx 4rpx 4rpx #ccc;
    background-color: rgb(251, 251, 251);
    padding: 80rpx;
	box-sizing: border-box;
  }
}
</style>
